package dao;

import java.util.List;

import model.Empresa;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import org.hibernate.criterion.Order;

import util.HibernateUtil;

public class EmpresaDAO {
    public EmpresaDAO() {
        session = HibernateUtil.getSessionFactory().openSession();
    }
    
    private Session session;

    public void insert(Empresa e){
        Transaction t = session.beginTransaction();
        session.merge(e);
        t.commit();
    }
    
    public void delete(Empresa e){
        Transaction t = session.beginTransaction();
        session.delete(e);
        t.commit();
    }

    public List<Empresa> findAll(){
        Criteria criteria = session.createCriteria(Empresa.class);
        return criteria.list();
    }

    public static void main(String[] args) {
        EmpresaDAO empresaDAO = new EmpresaDAO();
        for (Empresa e : empresaDAO.findAll()){
            System.out.println(e.getRazaosocial());
        }
        
        
    }   
    
    
}
